package org.github.manx98.jlibhac.tools.fssystem.romfs;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.github.manx98.jlibhac.common.math.Uint16;
import org.github.manx98.jlibhac.common.math.Uint32;
import org.github.manx98.jlibhac.common.math.Uint64;
import org.github.manx98.jlibhac.common.math.UnsignedNumber;

/**
 * @author Manx98
 * @version 1.0
 * @since 2022/10/5 0:32
 */
@AllArgsConstructor
@Data
public class RomEntryKey {
    public String Name = "";
    public int Parent;

    public Uint32 getRomHashCode() {
        return getRomHashCode(Parent, Name);
    }

    public static Uint32 getRomHashCode(int parent, String name) {
        UnsignedNumber hash = new Uint32(123456789L).xor(new Uint32(parent));
        for (char c : name.toCharArray()) {
            hash = hash.shiftLeft(27).or(hash.shiftRight(5)).xor(new Uint16(c));
        }
        return (Uint32) hash;
    }
}
